from flask import Blueprint, request, jsonify
from service.userService import *
from service import userService

user_bp = Blueprint('user_bp', __name__)


@user_bp.route('/', methods=['GET'])
def getAllUser():
    return getAllUserList()


@user_bp.route('/<id>', methods=['GET'])
def getOneUser(id):
    print(id)
    return userService.getOneUser(id)


@user_bp.route('/recommend/<id>', methods=['GET'])
def recommendUser(id):
    print(id)
    return userService.recommendUser(id)


@user_bp.route('/', methods=['POST'])
def login():
    data = request.get_json()
    print(data)
    username = data['username']
    password = data['password']
    return userService.login(username, password)


@user_bp.route('/register', methods=['POST'])
def registerUser():
    data = request.get_json()
    print(data)
    user = User(data['username'], data['password'], data['power'], data['picture'])
    return register(user)


@user_bp.route('/update', methods=['POST'])
def updateUser():
    data = request.get_json()
    print(data)
    user = User(data['username'], data['password'], data['power'], data['picture'])
    id=data['id']
    return userService.updateUser(id,user)


@user_bp.route('/delete', methods=['POST'])
def deleteUser():
    data = request.get_json()
    print(data)
    id = data['id']
    return userService.deleteUser(id)

